<!--头部公共部分-->
{include file="common/header" /}
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">财务</a>
        <a>
          <cite>订单管理</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="float:right" href="javascript:location.replace(location.href);"
       title="刷新">
        <i class="layui-icon layui-icon-refresh"></i></a>
</div>
<div class="layui-tab layui-tab-card" lay-filter="filter">

    <ul class="layui-tab-title">
        <li class="layui-this">订单管理</li>
        <li>业绩分配</li>
        <li>学费分配</li>
        <li>订单修改记录</li>
    </ul>

    <div class="layui-tab-content" >
        <div class="layui-tab-item layui-show">
            <div class="x-body">
                <div class="layui-row">
                    <div class="layui-form layui-col-md12 x-so layui-form-pane">
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" style="width: auto;" placeholder="签约时间" name="signing_date" id="start">
                        </div>
                        <div class="layui-input-inline">
                            <input type="text" name="contract_number" style="width: auto;" placeholder="订单编号" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-input-inline">
                            <select name="campus_id" lay-verify="required" lay-search="">
                                <option value="">选择校区</option>
                                {volist name="campus" id="campu"}
                                <option value="{$campu.id}">{$campu.campus_name}</option>
                                {/volist}s
                            </select>
                        </div>
                        <div class="layui-input-inline">
                            <input type="text" name="student_name" placeholder="学员姓名" autocomplete="off" class="layui-input">
                        </div>

                        <div class="layui-input-inline">
                            <select name="grade" lay-verify="required" lay-search="">
                                <option value="">学员年级</option>
                                {volist name="data[1]" id="grade"}
                                <option value="{$grade.id}">{$grade.name}</option>
                                {/volist}
                            </select>
                        </div>
                        <div class="layui-input-inline">
                            <button class="layui-btn" data-type="reload" id="search">
                                <i class="layui-icon layui-icon-search"></i>筛选
                            </button>
                            <button class="layui-btn layui-btn-danger" id="clear"><i
                                    class="layui-icon"></i>重置
                            </button>
                        </div>
                    </div>
                </div>
                <div class="site-demo-button" lay-filter="selBtn" id="typeclass">
                    <button class="layui-btn layui-btn-sm site-demo-active layui-btn-warm" data-type="all">全部订单</button>
                    <button class="layui-btn layui-btn-sm site-demo-active" data-type="stay">待收款订单</button>
                    <button class="layui-btn layui-btn-sm site-demo-active " data-type="part">部分收款订单</button>
                    <!--<button class="layui-btn site-demo-active" style="float: right;" data-type="today">导出</button>-->
                    <!--<button class="layui-btn site-demo-active layui-btn-warm" style="float: right;" data-type="all">导入</button>-->
                </div>
                <table class="layui-table" id="datalist" lay-filter="Event"></table>
            </div>
            <script type="text/html" id="barTable">
                {{# if(d.signing_type == 114){ }}
                <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="refund">线下储值退费</a>
                {{# } else if(d.signing_type != 114 && d.signing_type != -1){ }}
                <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="receivables">收款</a>
                <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="distribution">资金课时分配</a>
                <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="refund">线下订单退费</a>
                <a class="layui-btn layui-btn-xs" lay-event="edit">订单编辑</a>
                {{# } }}
                <!--
                <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="performance_allocation">业绩分配</a>
                -->
            </script>
        </div>
        <div class="layui-tab-item layui-show">
            <div id="achievement" class="x-body" style="visibility: hidden" class="clear:both;">

                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <fieldset class="layui-elem-field layui-field-title" >
                            <legend style="font-size: 18px;">校区业绩分配</legend>
                        </fieldset>
                        <div class="layui-form layui-col-md12 x-so layui-form-pane">
                            <div class="layui-input-inline">
                                <!--  <input type="text" name="campus_name" placeholder="请输入校区名字" autocomplete="off" class="layui-input"> -->
                                <select name="campus_name" lay-search="" lay-verify="required">
                                    <option selected value="">请选择校区</option>
                                    {foreach name="campus" id="vo"}
                                    <option value="{$vo.campus_name}">{$vo.campus_name}</option>
                                    {/foreach}
                                </select>
                            </div>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" style="width: auto;" placeholder="选择分配日期" name="allocation_campus_date" id="start_campus">
                            </div>
                            <div class="layui-input-inline">
                                <button class="layui-btn" id="search_all">
                                    <i class="layui-icon layui-icon-search"></i>筛选</button>
                                <button class="layui-btn layui-btn-danger" id="clear_all">
                                    <i class="layui-icon"></i>重置</button>
                            </div>


                        <table class="layui-hide" id="LAY_table_campus" lay-filter="table"></table>
                        <script type="text/html" id="barTable_campus">
                            <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="adjustment_campus">调整业绩</a>
                            <a class="layui-btn layui-btn-xs layui-btn-danger " lay-event="del_campus">删除</a>
                        </script>
                        </div>
                    </div>

                    <div class="layui-col-md6">
                        <fieldset class="layui-elem-field layui-field-title" >
                            <legend style="font-size: 18px;">个人业绩分配</legend>
                        </fieldset>
                        <div class="layui-form layui-col-md12 x-so layui-form-pane">
                            <div class="layui-input-inline">
                                <!--
                                <input type="text" name="adjustment_name" placeholder="请输分配人名字" autocomplete="off" class="layui-input">
                                -->
                                <select name="adjustment_name" lay-search="" lay-verify="required">
                                    <option value="">请输选择分配人</option>
                                 
                                </select>

                            </div>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" style="width: auto;" placeholder="选择分配日期" name="allocation_only_date" id="start_only">
                            </div>
                            <div class="layui-input-inline">
                                <button class="layui-btn" id="search_only">
                                    <i class="layui-icon layui-icon-search"></i>筛选</button>
                                <button class="layui-btn layui-btn-danger" id="clear_only">
                                    <i class="layui-icon"></i>重置</button>
                            </div>


                        <table class="layui-hide" id="LAY_table_only" lay-filter="table"></table>
                        <script type="text/html" id="barTable_only">
                            <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="adjustment_only">调整业绩</a>
                            <a class="layui-btn layui-btn-xs layui-btn-danger " lay-event="del_only">删除</a>
                        </script>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-tab-item">
            <div id="wodekehu" class="x-body" class="clear:both;">
                <div class="layui-row"
                     style="padding-left:20px;border-left:1px solid #e5e5e5;border-right:1px solid #e5e5e5;">
                    <div class="layui-form layui-col-md12 x-so layui-form-pane"  lay-filter="form-organization">
                        <div class="layui-input-inline">
                            <select name="campus_id_allocation" lay-search="">
                                <option value="">选择分配校区</option>
                                {volist name="campus" id="campu"}
                                <option value="{$campu.id}">{$campu.campus_name}</option>
                                {/volist}
                            </select>
                        </div>
                        <div class="layui-input-inline">
                            <input type="text" name="contract_number_allocation" style="width: auto;" placeholder="请输入订单编号" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" style="width: auto" placeholder="分配日期" name="allocation_date" id="start_allocation">
                        </div>
                        <div class="layui-input-inline">
                            <button class="layui-btn" id="search_allocation">
                                <i class="layui-icon layui-icon-search"></i>筛选</button>
                            <button class="layui-btn layui-btn-danger" id="clear_allocation">
                                <i class="layui-icon"></i>重置</button>
                        </div>
                    </div>
                </div>
                <table class="layui-hide" id="LAY_table_user" lay-filter="table"></table>

            </div>
        </div>
        <div class="layui-tab-item">
            <div id="modification" class="x-body" class="clear:both;">
                <div class="layui-row"
                     style="padding-left:20px;border-left:1px solid #e5e5e5;border-right:1px solid #e5e5e5;">
                    <div class="layui-form layui-col-md12 x-so layui-form-pane"  lay-filter="form-organization">
                        <div class="layui-input-inline">
                            <input type="text" name="student_name_modifiy" placeholder="请输入学员姓名" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-input-inline">
                            <input type="text" name="contract_number_modifiy" placeholder="订单编号" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" style="width: auto" placeholder="选择修改日期" name="change_date" id="start_modifiy">
                        </div>

                        <div class="layui-input-inline">
                            <button class="layui-btn" id="search_modifiy">
                                <i class="layui-icon layui-icon-search"></i>筛选</button>
                            <button class="layui-btn layui-btn-danger" id="clear_modifiy">
                                <i class="layui-icon"></i>重置</button>
                        </div>
                    </div>
                </div>
                <table class="layui-hide" id="LAY_table_user_modifiy" lay-filter="table"></table>

            </div>
        </div>
    </div>
</div>
<!--底部公共部分-->
{include file="common/footer" /}
<script>
    layui.use(['table', 'laydate', 'element', 'layer'], function () {
        let table = layui.table,
            laydate = layui.laydate,
            layer = layui.layer,
            element = layui.element,
            $ = layui.$;
        let loading = layer.load();

        element.on('tab(filter)', function(data){
            console.log(this); //当前Tab标题所在的原始DOM元素
            console.log(data.index); //得到当前Tab的所在下标
            console.log(data.elem); //得到当前的Tab大容器

            if(data.index === 1){
                document.getElementById("achievement").style.visibility="visible";
            }else{
                document.getElementById("achievement").style.visibility="hidden";
            }


        });


        //日期
        laydate.render({
            elem: '#start',
            range: true
            ,trigger: 'click'
        });
        //方法级渲染
        let tableIns = table.render({
            elem: '#datalist'
            , url: '{:url("Contract/lists")}'
            , method: 'POST'
			, where: {type: 'all'}
            , toolbar: 'true' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
            , defaultToolbar: ['print', 'exports'] // 筛选图标
            , loading: true
            , limits: [10,20,30,40,50,60,70,80,90,10000000]
            , parseData: function (res) { //res 即为原始返回的数据
                if (res.code === 1) {
                    res.code = 0;
                } else {
                    res.code = -1;
                }
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.data //解析数据列表
                };
            }, cols: [[
                // {type: 'checkbox'},
                {field: 'contract_number', title: '订单编号',style:'color:#01AAED;font-weight: bold;', width: 200, sort: true, fixed: false, align: 'center'},
                {field: 'student_name', title: '学员姓名', width: 90, align: 'center'},
                {field: 'grade', title: '年级', width: 80, align: 'center'},
                {field: 'signing_date', title: '签约时间', width: 110, align: 'center'},
                {field: 'campus_name', title: '签约校区', width: 150, align: 'center'},
                {field: 'contractor', title: '签约人', width: 120, align: 'center'},
                {field: 'payee_text', title: '收款人', width: 120, align: 'center'},
           //     {field: 'contract_type', title: '订单类型', width: 90, align: 'center'},
                {field: 'signing_type_text', title: '类型', width: 90, align: 'center'},
                {field: 'input_type_text', title: '录入类型', width: 90, align: 'center'},
                {field: 'total_contract', title: '合同总额', width: 150, align: 'center'},
                {field: 'total_amount', title: '应收', width: 90, align: 'center'},
                {field: 'net_receipts', title: '实际收费', width: 180, align: 'center'},
                {field: 'amount', title: '报读项目总收费', width: 180, align: 'center'},
                {field: 'amount_course', title: '报读课程收费', width: 180, align: 'center'},
                {field: 'amount_grades', title: '报读班级收费', width: 180, align: 'center'},
                {field: 'amount_goods', title: '购买物品收费', width: 180, align: 'center'},
                {field: 'amount_course_balance', title: '报读课程余额', width: 180, align: 'center'},
                {field: 'amount_grades_balance', title: '报读班级余额', width: 180, align: 'center'},
      //          {field: 'amount_goods_balance', title: '购买物品余额', width: 180, align: 'center'},
                {field: 'stay_amount', title: '欠费', width: 90, align: 'center'},
                {field: 'expenditure', title: '课消', width: 90, align: 'center'},
                {field: 'balance', title: '学费余额', width: 90, align: 'center'},
                {field: 'storedvalue', title: '储值', width: 90, align: 'center'},
                {field: 'stay_distributed', title: '待分配', width: 90, align: 'center'},
                {field: 'preferential', title: '优惠', width: 90, align: 'center'},
                {title: '操作', fixed: 'right', width: 330, align: 'center', toolbar: '#barTable'}
            ]]
            , height: 'full-180'
            , page: true
            , title: '订单管理报表'
            , done: function () {
                layer.close(loading);
            }
        });

        //分类选择
        $('.site-demo-active').on('click', function () {
            $('#typeclass').find('button').removeClass('layui-btn-warm');
            $(this).addClass('layui-btn-warm');
            let type = $(this).data('type');
            tableIns.reload({
                where: {
                    'type': type
                }
            });
        });

        table.on('checkbox(Event)', function (obj) {
        });

        //搜索项
        $('#search').click(function () {
            var field = {};
            field.campus_id = $('select[name=campus_id] option:selected').val();
            field.grade = $('select[name=grade] option:selected').val();
            field.student_name = $('input[name=student_name]').val();
            field.contract_number = $('input[name=contract_number]').val();

            var create_date_rang = $('input[name=signing_date]').val();
            if(create_date_rang.length > 0){
                strs_date=create_date_rang.split("-"); //字符分割
                field.start_date = strs_date[0]+'-'+strs_date[1]+'-'+strs_date[2];
                field.end_date = strs_date[3]+'-'+strs_date[4]+'-'+strs_date[5];
            }


            console.log(field);
            tableIns.reload({
                where: field,
                method: 'POST',
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });
        //清除
        $('#clear').click(function () {
            $('.layui-form-pane').find('.layui-input-inline').each(function (index, element) {
                $(element).find('input[type=text]').val('');
                $(element).find('select').val('');
            })
            tableIns.reload({
                where: {
                    'contract_number': '',
                    'campus_id': '',
                    'grade': '',
                    'student_name': '',
                    'signing_date': '',
                },
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });


        /**********业绩分配**********/
        /**校区*/
        //日期
        laydate.render({
            elem: '#start_campus',
            range: true
            ,trigger: 'click'
        });
            //数据表格 方法级渲染
        var tableIns_campus = table.render({
                elem: '#LAY_table_campus'
                , url: '{:url("finance/campuslists")}'
                , method: 'POST'
                , loading: true
                , parseData: function (res) { //res 即为原始返回的数据
                    if (res.code === 1) {
                        res.code = 0;
                    } else {
                        res.code = -1;
                    }
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.message, //解析提示文本
                        "count": res.data.total, //解析数据长度
                        "data": res.data.data //解析数据列表
                    };
                },
                cols: [[
                    {field: 'id', title: 'ID', width: 50, align: 'center'
                    },{field: 'campus_id_all_text', title: '校区', style:'color:#01AAED;font-weight: bold;', width: 150, align: 'center'
                    },{field: 'contract_number', title: '分配订单编号', width: 200, align: 'center'
                    },{field: 'assignment_all_text', title: '收费归属', width: 100, align: 'center'
                    },{field: 'rate_all', title: '比率', width: 100, align: 'center'
                    },{field: 'rate_all_money', title: '所分金额(元)',style:'color:#01AAED;font-weight: bold;', width: 120, align: 'center'
                    },{field: 'amount_already_all', title: '付款金额(元)', style:'color:#FF5722;font-weight: bold;', width: 120, align: 'center'
                    },{field: 'update_time', title: '生成时间', width: 220, align: 'center'
                    },{fixed: 'right', title: '操作', width: 140, align: 'center', toolbar: '#barTable_campus'}
                ]]
                , height: 'full-300'
                , page: true
                , done: function () {
                    $("[data-field='id']").css('display','none');
                    layer.close(loading);
                }
            });

        /**个人*/
        //日期
        laydate.render({
            elem: '#start_only',
            range: true
            ,trigger: 'click'
        });

        var tableIns_only = table.render({
            elem: '#LAY_table_only'
            , url: '{:url("finance/onlylists")}'
            , method: 'POST'
            , loading: true
            , parseData: function (res) { //res 即为原始返回的数据
                if (res.code === 1) {
                    res.code = 0;
                } else {
                    res.code = -1;
                }
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.data //解析数据列表
                };
            },
            cols: [[
                {field: 'id', title: 'ID', width: 50, align: 'center'
                },{field: 'payee_only_text',style:'color:#01AAED;font-weight: bold;', title: '分配人', width: 150, align: 'center'
                },{field: 'contract_number', title: '分配订单编号', width: 200, align: 'center'
                },{field: 'assignment_only_text', title: '收费归属', width: 100, align: 'center'
                },{field: 'rate_only', title: '比率', width: 100, align: 'center'
                },{field: 'rate_only_money', title: '所分金额(元)', style:'color:#01AAED;font-weight: bold;', width: 120, align: 'center'
                },{field: 'amount_already_only', title: '付款金额(元)', style:'color:#FF5722;font-weight: bold;', width: 120, align: 'center'
                },{field: 'update_time', title: '生成时间', width: 220, align: 'center'
                },{fixed: 'right', title: '操作', width: 140, align: 'center', toolbar: '#barTable_only'}
            ]]
            , height: 'full-300'
            , page: true
            , done: function () {
                $("[data-field='id']").css('display','none');
                layer.close(loading);
            }
        });


        //搜索项校区业绩
        $('#search_all').click(function () {
            var field = {};
            field.campus_id_all_text = $('select[name=campus_name]').val();
            var create_date_rang = $('input[name=allocation_campus_date]').val();
            if(create_date_rang.length > 0){
                strs_date=create_date_rang.split("-"); //字符分割
                field.start_date = strs_date[0]+'-'+strs_date[1]+'-'+strs_date[2];
                field.end_date = strs_date[3]+'-'+strs_date[4]+'-'+strs_date[5];
            }

            console.log(field);
            tableIns_campus.reload({
                where: field,
                method: 'POST',
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });//清除校区业绩
        $('#clear_all').click(function () {
            $('.layui-form-pane').find('.layui-input-inline').each(function (index, element) {
                $(element).find('input[type=text]').val('');
                $(element).find('select').val('');
            })
            tableIns_campus.reload({
                where: {
                    'campus_id_all_text': '',
                    'allocation_campus_date':''
                },
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });

        //搜索项个人业绩
        $('#search_only').click(function () {
            var field = {};
            field.payee_only_text = $('select[name=adjustment_name]').val();
            var create_date_rang = $('input[name=allocation_only_date]').val();
            if(create_date_rang.length > 0){
                strs_date=create_date_rang.split("-"); //字符分割
                field.start_date = strs_date[0]+'-'+strs_date[1]+'-'+strs_date[2];
                field.end_date = strs_date[3]+'-'+strs_date[4]+'-'+strs_date[5];
            }
            console.log(field);
            tableIns_only.reload({
                where: field,
                method: 'POST',
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });//清除个人业绩
        $('#clear_only').click(function () {
            $('.layui-form-pane').find('.layui-input-inline').each(function (index, element) {
                $(element).find('input[type=text]').val('');
                $(element).find('select').val('');
            })
            tableIns_only.reload({
                where: {
                    'payee_only_text': '',
                    'allocation_only_date':''
                },
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });


        /************学费***************/
        //日期
        laydate.render({
            elem: '#start_allocation',
            range: true
            ,trigger: 'click'
        });

        //数据表格 方法级渲染
        var tableIns_allocation = table.render({
            elem: '#LAY_table_user'
            , url: '{:url("Finance/capital_allocation_record")}'
            , method: 'POST'
            , loading: true
            , parseData: function (res) { //res 即为原始返回的数据
                if (res.code === 1) {
                    res.code = 0;
                } else {
                    res.code = -1;
                }
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.data //解析数据列表
                };
            },
            cols: [[
                {field: 'contract_number', title: '订单编号',style:'color:#01AAED;font-weight: bold;',  width: 200, sort: true, fixed: false, align: 'center'
                }, {field: 'capital_allocation_id', style:'font-weight: bold;',title: '资金分配ID', width: 200, align: 'center',edit: 'text'
                }, {field: 'contractor', title: '签单人',style:'font-weight: bold;', width: 150, align: 'center'
                }, {field: 'student_name', title: '学员姓名',style:'font-weight: bold;', width: 150, align: 'center'
                }, {field: 'create_time', title: '分配日期',style:'font-weight: bold;', width: 200, align: 'center'
                }, {field: 'distributive_person', title: '分配人', style:'font-weight: bold;',width: 150, align: 'center'
                }, {field: 'campus_name', title: '分配校区', style:'font-weight: bold;',width: 150, align: 'center'
                }, {field: 'project_type_text', title: '项目类型',style:'font-weight: bold;', width: 150, align: 'center'
                }, {field: 'project_name', title: '项目名称',style:'font-weight: bold;', width: 300, align: 'center'
                }, {field: 'project_class_type', title: '班型',style:'font-weight: bold;', width: 150, align: 'center'
                }, {field: 'allotted_quantity', title: '分配数量',style:'font-weight: bold;', width: 150, align: 'center'
                }, {field: 'allocation_fund', title: '分配资金',style:'font-weight: bold;', width: 150, align: 'center'
                }, {field: 'type', title: '类型', width: 150, style:'font-weight: bold;', align: 'center'
                }
            ]]
            , height: 'full-180'
            , page: true
            , done: function () {
                layer.close(loading);
            }
        });
        //搜索项
        $('#search_allocation').click(function () {
            var field = {};
            field.contract_number = $('input[name=contract_number_allocation]').val();
            field.campus_id = $('select[name=campus_id_allocation]').val();
            var create_date_rang = $('input[name=allocation_date]').val();
            if(create_date_rang.length > 0){
                strs_date=create_date_rang.split("-"); //字符分割
                field.start_date = strs_date[0]+'-'+strs_date[1]+'-'+strs_date[2];
                field.end_date = strs_date[3]+'-'+strs_date[4]+'-'+strs_date[5];
            }
            console.log(field);
            tableIns_allocation.reload({
                where: field,
                method: 'POST',
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });//清除
        $('#clear_allocation').click(function () {
            $('.layui-form-pane').find('.layui-input-inline').each(function (index, element) {
                $(element).find('input[type=text]').val('');
                $(element).find('select').val('');
            })
            tableIns_allocation.reload({
                where: {
                    'contract_number_allocation': '',
                    'allocation_date': '',
                    'campus_id': '',
                },
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });


        /************订单修改******/
        //日期
        laydate.render({
            elem: '#start_modifiy',
            range: true
            ,trigger: 'click'
        });

        //数据表格 方法级渲染
        var tableIns_modifiy = table.render({
            elem: '#LAY_table_user_modifiy'
            , url: '{:url("Finance/contract_modification_record")}'
            , method: 'POST'
            , loading: true
            , parseData: function (res) { //res 即为原始返回的数据
                if (res.code === 1) {
                    res.code = 0;
                } else {
                    res.code = -1;
                }
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.data //解析数据列表
                };
            },
            cols: [[
                {field: 'student_name', title: '学员姓名',style:'color:#01AAED;font-weight: bold;', width: 100, align: 'center'
                },{field: 'contract_number', title: '订单编号', width: 200, align: 'center'
                }, {field: 'contractor', title: '签约人', width: 100, align: 'center'
                },  {field: 'change_modifier', title: '修改人', width: 100, align: 'center'
                }, {field: 'action', title: '动作', width: 200, align: 'center'
                },{field: 'change_front', title: '修改前(值)', width: 200, align: 'center'
                },{field: 'change_after', title: '修改后(值)', width: 200, align: 'center'
                }, {field: 'create_time', title: '修改时间', width: 200, align: 'center'
                }
            ]]
            , height: 'full-180'
            , page: true
            , done: function () {
                layer.close(loading);
            }
        });

        //搜索项
        $('#search_modifiy').click(function () {
            var field = {};
            field.student_name = $('input[name=student_name_modifiy]').val();
            field.contract_number = $('input[name=contract_number_modifiy]').val();
            var create_date_rang = $('input[name=change_date]').val();
            if(create_date_rang.length > 0){
                strs_date=create_date_rang.split("-"); //字符分割
                field.start_date = strs_date[0]+'-'+strs_date[1]+'-'+strs_date[2];
                field.end_date = strs_date[3]+'-'+strs_date[4]+'-'+strs_date[5];
            }

            console.log(field);
            tableIns_modifiy.reload({
                where: field,
                method: 'POST',
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });//清除
        $('#clear_modifiy').click(function () {
            $('.layui-form-pane').find('.layui-input-inline').each(function (index, element) {
                $(element).find('input[type=text]').val('');
                $(element).find('select').val('');
            })
            tableIns_modifiy.reload({
                where: {
                    'student_name_modifiy': '',
                    'contract_number_modifiy': '',
                    'change_date': '',
                },
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });

        //监听工具条
        table.on('tool(Event)', function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === 'edit') {
                if(data.contract_number === '合计'){
                    layer.msg('【合计】栏目不可选中');
                    return;
                }

                $.ajax({
                    url: '{:url("Contract/edit_backcontract_lists")}',
                    method: "post",
                    data: {cid: data.id, campus_id: data.campus_id},
                    success: function (result) {
                        console.log(result);
                        if (result.code === 1) {
                            var url = '{:url("contract/edit")}?cid=' + data.id + '&campus_id=' + data.campus_id + '&sid='+ data.student_id + '&status_infos='+ data.status_infos;
                            location.href = url;
                        }
                    },
                });
            } else if (layEvent === 'receivables') {
                if(data.contract_number === '合计'){
                    layer.msg('【合计】栏目不可选中');
                    return;
                }
                let url = '{:url("Contract/receivables")}?id=' + data.id + '&receivables_status=' + 1;
                layer.open({
                    type: 2,
                    skin: 'layui-layer-lan',
                    title: '订单收款：' + data.student_name,
                    closeBtn: 2,
                    shadeClose: false,
                    area: ['95%', '98%'],
                    content: url,
                    cancel: function(index, layero){
                        $.ajax({
                            url: '/admin/contract/close',
                            method: "post",
                            beforeSend: function () {
                                isLoad = layer.load(0, {
                                    shade: false
                                }); //0代表加载的风格，支持0-2
                            },
                            success: function (result) {
                                if (result.code === 1) {
                                    layer.close(index)
                                }

                            },
                            complete: function () {
                                layer.close(isLoad)
                            },
                            error: function (error) {
                                console.log(error)
                            }
                        });
                        return false;
                    },


                    end:function () {

                        location.reload();
                    }

                });
            } else if (layEvent == 'distribution') {
                if(data.contract_number === '合计'){
                    layer.msg('【合计】栏目不可选中');
                    return;
                }
                var url = '{:url("Contract/getcampuslist")}?contract_number=' + data.contract_number + "&amount=" + data.amount + "&stay_distributed=" + data.stay_distributed;
                layer.open({
                    type: 2,
                    title: '资金课时分配',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['98%', '95%'],
                    content: url,
                    success: function (layero, index) {
                        var body = layer.getChildFrame('body', index);
                        body.find("#contract_number").html('<font  color="#46A3FF">' + data.contract_number + '</font>');
                        body.find("#total_amount").html('<font  color="#46A3FF">' + data.total_amount + '</font>');
            //            body.find("#amount").html('<font  color="#46A3FF">' + data.amount + '</font>');
                        //  body.find("#signing_date").html('<font  color="#46A3FF">' + data.signing_date + '</font>');
                    },
                    end:function () {

                        location.reload();
                    }
                });


            } else if (layEvent === 'alert') {
                if(data.contract_number === '合计'){
                    layer.msg('【合计】栏目不可选中');
                    return;
                }
                layer.open({
                    type: 2,
                    title: '学员：' + data.student_name + '&emsp;' + '订单编号：' + data.contract_number,
                    shadeClose: true,
                    shade: 0.8,
                    area: ['50%', '50%'],
                    content: url


                });
            }else if(layEvent == 'performance_allocation'){  //业绩分配
                if(data.contract_number === '合计'){
                    layer.msg('【合计】栏目不可选中');
                    return;
                }
                let url = '{:url("Contract/performance")}?id='+ data.id;
                layer.open({
                    type: 2,
                    skin: 'layui-layer-lan',
                    title: '业绩分配',
                    closeBtn: 2,
                    shadeClose: false,
                    area: ['80%', '90%'],
                    content: url
                });
            }else if(layEvent == 'refund'){  //退款
                if(data.contract_number === '合计'){
                    layer.msg('【合计】栏目不可选中');
                    return;
                }

                if(data.signing_type == 114){
                    let url = '{:url("Contract/refund")}?id='+ data.id;
                    let title = '储值余额线下退费';
                    console.log(data.id)
                    layer.open({
                        type: 2,
                        skin: 'layui-layer-lan',
                        title: title,
                        closeBtn: 2,
                        shadeClose: false,
                        area: ['80%', '50%'],
                        content: url
                    });
               }else{
                    let url = '{:url("Contract/refund_tuition")}?id='+ data.id;
                    let title = '学费余额线下退费';
                    console.log(data.id)
                    layer.open({
                        type: 2,
                        skin: 'layui-layer-lan',
                        title: title,
                        closeBtn: 2,
                        shadeClose: false,
                        area: ['95%', '95%'],
                        content: url
                    });
                }

            }
        });
        //监听工具条
        table.on('tool(table)', function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === 'del_campus') { //删除
                layer.confirm('真的删除这条校区业绩么', function (index) {
                    $.post("{:url('finance/campus_del')}", {
                        id: data.id
                    }, function (result) {
                        if (result.code === 1) {
                            layer.msg(result.msg, {
                                time: 2000
                            });
                            setTimeout(function () {
                                tableIns_campus.reload();
                            }, 1000)
                        } else {
                            layer.msg(result.msg, {
                                icon: 2,
                                time: 2000
                            });
                        }
                    }, "json")
                });

            }else if (layEvent === 'del_only') { //删除
                layer.confirm('真的删除这条个人业绩数据么', function (index) {
                    $.post("{:url('finance/only_del')}", {
                        id: data.id
                    }, function (result) {
                        if (result.code === 1) {
                            layer.msg(result.msg, {
                                time: 2000
                            });
                            setTimeout(function () {
                                tableIns_only.reload();
                            }, 1000)
                        } else {
                            layer.msg(result.msg, {
                                icon: 2,
                                time: 2000
                            });
                        }
                    }, "json")
                });

            }else if (layEvent === 'adjustment_campus'){   //调整校区业绩

                let url = '{:url("Finance/performance_all")}?id='+ data.id;
                layer.open({
                    type: 2,
                    skin: 'layui-layer-lan',
                    title: '校区业绩调整',
                    closeBtn: 2,
                    shadeClose: false,
                    area: ['50%', '30%'],
                    content: url,
                    end:function () {

                        tableIns_campus.reload();
                    }
                });


            }else if (layEvent === 'adjustment_only'){   //调整个人业绩

                let url = '{:url("Finance/performance_only")}?id='+ data.id;
                layer.open({
                    type: 2,
                    skin: 'layui-layer-lan',
                    title: '个人业绩调整',
                    closeBtn: 2,
                    shadeClose: false,
                    area: ['50%', '30%'],
                    content: url,
                    end:function () {

                        tableIns_only.reload();
                    }
                });


            }

        });

    });
</script>